#pragma once
#include"Singleton.h"
#include<queue>
#include<thread>
#include"CSession.h"
#include<map>
#include<functional>
#include"const.h"
#include<json/json.h>
#include<json/value.h>
#include<json/reader.h>

typedef function<void (shared_ptr<CSession>, const short& msg_id, const string& msg_data)>  FunCallBack;
//函数返回值为void,三个参数

class LogicSystem:public Singleton<LogicSystem>
{
	friend class Singleton<LogicSystem>;//因为LogicSystem构造函数为私有,而单例模板类里面又有new T()操作
public:
	~LogicSystem();//为了析构智能指针的时候系统能访问到析构函数
	void PostMsgToQue(shared_ptr<LogicNode> msg);
private:
	LogicSystem();//单例类构造为私有
	void RegisterCallBacks();//将消息id和回调函数绑定起来
	void HelloWordCallBack(shared_ptr<CSession>, const short& msg_id, const string& msg_data);
	void DealMsg();
	std::queue<shared_ptr<LogicNode>> _msg_que;
	std::mutex _mutex;
	std::condition_variable _consume;
	std::thread _worker_thread;//从逻辑队列取数据

	bool _b_stop;//
	std::map<short, FunCallBack> _fun_callback;
};

